package com.ophiux.common.tools.util;

import java.util.List;

public class ListUtil {
	public static String list2str(List<String> data) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < data.size(); i++) {
			sb.append(data.get(i));
			sb.append(i < data.size() - 1 ? "," : "");
		}
		return sb.toString();
	}

	public static <T> int findIndex(List<T> data, T s) {
		for (int i = 0; i < data.size(); i++) {
			if (!data.get(i).equals(s))
				continue;
			return i;
		}
		return -1;
	}

	/**
	 * If the array is empty, the array is undefined, then back into the true value,
	 * otherwise false
	 */
	public static <T> boolean isBlank(List<T> list) {
		boolean flag = false;
		try {
			if (list == null || list.size() == 0) {
				flag = true;
			}
		} catch (Exception e) {
			// TODO: handle exception
			flag = true;
		}
		return flag;
	}

	/**
	 * If the contents of the array is not empty and the array is undefined, then
	 * back into the true value, otherwise false
	 * 
	 * @param list
	 * @return
	 */
	public static <T> boolean isNotBlank(List<T> list) {
		boolean flag = true;
		try {
			if (list == null || list.size() == 0) {
				flag = false;
			}
		} catch (Exception e) {
			// TODO: handle exception
			flag = false;
		}
		return flag;
	}
}
